﻿@{
    Layout = "~/Views/Shared/OA/_Splitter.cshtml";
    var domain = IComService.Current.GetSettingValue("BaiYi", "HostName");
    var url = string.Format(domain + "/CMS/Articles/Detail/", IManagerAuth.Current.User.TenantId);
}
@section Toolbar
{
    @Html.MyNet().Button(new ButtonOptions { Text = "选择", Click = "choose" })
}
@section Menu
{

}
@section Query
{
    @Html.Partial("_Query", new ArticleCondition())
}
@section Tree
{
    <div id="tree" class="tree">
    </div>
}
@section Main
{
    @Html.Hidden("url", url)
    <div id="grid" class="grid">
    </div>
    <div id="pager" class="pager">
    </div>
}
<script type="text/javascript">

    var url = "/CMS/Article/";
    var urlCatalog = "/CMS/Catalog/";

    jQuery(function () {
        $("#tree").kendoTreeView(
        {
            dataSource:
            {
                transport: { read: urlCatalog + "ReadForParent?ParentKey=Article" },
                schema:
                {
                    data: "Data",
                    model: { children: "childs" },
                    errors: "Errors"
                },
                error: function (e) {
                    alert(e.errors);
                }
            },
            dataBound: onDataBound,
            select: onSelect,
            dragend: onDragend
        });
    });

    function read() {
        query.catalogId = treeSelected();

        $.ajax
        ({
            url: url + "Read",
            data: query,
            type: "post",
            error: disposeError,
            success: function (result) {

                if (disposeException(result)) return;
                bind(result);
            }
        });
    }

    function choose() {
        if (!gridSelected()) return alert("未选中任何数据！");
        var url = $("#url").val() + gridSelected()[0];
        top.callback({ Id: gridSelected()[0], Url: url, Title: gridSelectedHidden("Title")[0] });
        if (typeof (isClose) != 'undefined' && isClose == false) {
            return;
        }
        top.winClose();
    }

</script>
